package com.idbk.chargestation.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.idbk.chargestation.R;
import com.idbk.chargestation.bean.JsonChargeRefresh;

import java.util.Locale;

public class DialogBill extends Dialog implements View.OnClickListener {

    private JsonChargeRefresh result;

    public DialogBill(Context context, JsonChargeRefresh result) {
        super(context);
        this.result = result;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        View view = getLayoutInflater().inflate(R.layout.dialog_bill_detail, new LinearLayout(getContext()), false);
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        setContentView(view);
        if (getWindow() != null) {
            getWindow().setBackgroundDrawableResource(android.R.color.transparent);
            getWindow().setGravity(Gravity.CENTER);
        }

        BillHold billHold = new BillHold();
        billHold.initView(view);
        billHold.fillData(result);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.text_ok:
                dismiss();
                break;
            default:
                break;
        }
    }


    private static class BillHold {

        private TextView mStartTime, mCostMoney, mPoint, mPileSn, mChargeTime, mElect, mServiceCost, mChargeMoney;

        private void initView(View parent) {
            mStartTime = (TextView) parent.findViewById(R.id.detail_time);
            mCostMoney = (TextView) parent.findViewById(R.id.textview_money);
            mPoint = (TextView) parent.findViewById(R.id.textview_point);
            mPileSn = (TextView) parent.findViewById(R.id.textview_booksn);
            mChargeTime = (TextView) parent.findViewById(R.id.textview_chargetime);
            mElect = (TextView) parent.findViewById(R.id.textview_electricity);
            mServiceCost = (TextView) parent.findViewById(R.id.textview_time);
            mChargeMoney = (TextView) parent.findViewById(R.id.textview_totalcost);
        }

        private void fillData(JsonChargeRefresh result) {
            mStartTime.setText(result.startTime);
            mCostMoney.setText(String.format(Locale.CHINA, "%.2f", result.subChargeMoney));
            mPoint.setText(result.pointName);
            mPileSn.setText(result.pileSn);
            String charge = result.chargeTime + "分钟";
            mChargeTime.setText(charge);
            String elect = String.format(Locale.CHINA, "%.2f", result.quantity) + "度";
            mElect.setText(elect);
            String cost = String.format(Locale.CHINA, "%.2f", result.serverMoney) + "元";
            mServiceCost.setText(cost);
            String money = String.format(Locale.CHINA, "%.2f", result.chargeMoney) + "元";
            mChargeMoney.setText(money);
        }
    }


}
